package sort;

public class InsertionSort {

    public static void main(String args[]) {
	int[] data = { 4, 1, 7, 8, 9, 3, 2 };
	sort(data);
	for (int i = 0; i < data.length; i++) {
	    System.out.print(data[i] + ", ");
	}
    }

    private static void sort(int[] data) {
	int j, pivot;
	for (int i = 1; i < data.length; i++) {
	    pivot = data[i];
	    for (j = i - 1; j >= 0 && data[j] > pivot; j--) {
		data[j + 1] = data[j];
	    }
	    data[j + 1] = pivot;
	}
    }
}
